/**
 * Created by zhaojing on 2017/5/22.
 */



export default {

    /**
     * 获取首字母
     * @param name
     * @returns {string}
     */
    getFirstLetterByName(name) {
        name = name + '';
        return name.substring(0, 1);
    },

   /**
    * 获取全局唯一表示 uuid
    * */

    getUuid() {
        let d = new Date().getTime();
        let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
            let r = (d + Math.random()*16)%16 | 0;
            d = Math.floor(d/16);
            return (c=='x' ? r : (r&0x3|0x8)).toString(16);
        });
        return uuid;
    },

    /**
     * 比较两者价格的前no位数是否相同
     * @param currentPrice
     * @param lastPrice
     * @param no
     * @returns {boolean}
     */
    isDiffPrice(currentPrice, lastPrice, no) {
        let len = currentPrice.length;
        let index = len - no;
        let currentPrefix = currentPrice.substring(0, index);
        let lastPrefix = lastPrice.substring(0, index);
        if (currentPrefix !== lastPrefix) {
            return true;
        } else {
            return false;
        }
    },

    /**
     * 设置价格深浅程度
     * @param text
     * @param no
     * @param type
     */
    getLowPriceText(text, no, type) {
        let result;
        let len = text.length;
        let index = len - no;
        let prefix = text.substring(0, index);
        let suffix = text.substring(index);
        type = type.toLowerCase();

        if (type === 'buy') {
            result = `<span class="fn-color-buy-deep">${prefix}</span><span class="fn-color-buy">${suffix}</span>`;
        } else {
            result = `<span class="fn-color-sell-deep">${prefix}</span><span class="fn-color-sell">${suffix}</span>`;
        }
        return result;

    },

    /**
     * 获取高亮价格
     * @param text
     * @param type
     * @returns {*}
     */
    getHighPriceText(text, type) {
        let result;
        type = type.toLowerCase();
        if (type === 'buy') {
            result = `<span class="fn-color-buy">${text}</span>`;
        } else {
            result = `<span class="fn-color-sell">${text}</span>`;
        }
        return result;
    },

    /**
     * 获取中间面板的高度
     */
    getMdHeight() {
        const HEIGHT_NAV = 50;
        const HEIGHT_FOOTER = 0;
        const HEIGHT_FORM_BOTTOM = 246;
        const HEIGHT_SPACE = 0;
        return (document.documentElement.clientHeight || window.innerHeight) - (HEIGHT_NAV + HEIGHT_FOOTER + HEIGHT_FORM_BOTTOM + HEIGHT_SPACE);
    }


}